package com.home.qh.webapp.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.home.qh.model.TransCtrType;
import com.home.qh.service.CountryManager;
import com.home.qh.service.TransCtrTypeManager;

@Controller
public class TransCtrTypeController {
	private transient final Log log = LogFactory.getLog(TransCtrTypeController.class);
	private TransCtrTypeManager transCtrTypeManager;
	private CountryManager countryManager;

	@Autowired
	private ApplicationContext context;

	@Autowired
	public void setTransCtrTypeManager(TransCtrTypeManager transCtrTypeManager) {
		this.transCtrTypeManager = transCtrTypeManager;
	}

	@Autowired
	public void setCountryManager(CountryManager countryManager) {
		this.countryManager = countryManager;
	}

	@RequestMapping(value = "/admin/transCtrTypeList.*", method = { RequestMethod.GET,
			RequestMethod.POST })
	public ModelAndView listCities(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		if (log.isDebugEnabled()) {
			log.debug("entering 'handleRequest' method...");
		}

		TransCtrType transCtrTypeSearch = new TransCtrType();
		String paramValue = request.getParameter("name");
	
		if (paramValue != null && !"".equalsIgnoreCase(paramValue.trim())
				&& !"null".equalsIgnoreCase(paramValue)) {
			transCtrTypeSearch.setCode(paramValue);
			transCtrTypeSearch.setName(paramValue);
		}
	

		ModelAndView view = new ModelAndView("admin/transCtrTypeList");
		view.addObject("countryList", countryManager.getAll());
		view.addObject("transCtrTypeSearch", transCtrTypeSearch);

		view.addObject("transCtrTypeList",	transCtrTypeManager.getTransCtrTypeByTransCtrType(transCtrTypeSearch, null, false, -1, -1));
		return view;

	}

}
